package com.ch8.demo01;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @author woldier
 * @version 1.0
 * @description TODO
 * @date 2023/5/16 18:54
 **/
@Slf4j(topic = "c.Thread")
public class Demo01 {
    public static void main(String[] args) {
        ThreadPool threadPool = new ThreadPool(2, 1, TimeUnit.SECONDS, 2,(queue, task) -> {queue.offer(task,2000,TimeUnit.MILLISECONDS);});
        for (int i = 0; i < 3; i++) {
            int some = i;
            new Thread(()->{
                threadPool.execute(() -> {
                    log.debug("执行" + some);
                    try {
                        TimeUnit.SECONDS.sleep(2);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                });
            },"thread"+some).start();
        }
    }
}
